/**
 * 
 */
package com.yam.michael.hibernate.dao.impl;

import java.io.Serializable;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xunjia.exception.XunjiaException;
import com.yam.michael.hibernate.dao.CompanyDao;
import com.yam.michael.hibernate.pojo.Company;

/**
 * @author michael
 *
 */
public class CompanyDaoImpl extends HibernateDaoSupport implements CompanyDao,Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1041709905122290134L;
	//日志
	private static final Logger logger = Logger.getLogger(CompanyDaoImpl.class); 

	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.CompanyDao#addCompany(com.yam.michael.hibernate.pojo.Company)
	 * 增加企业
	 */
	@Override
	public Long addCompany(Company company) throws XunjiaException {
		try {
			return (Long) this.getHibernateTemplate().save(company);
		} catch (DataAccessException e) {
			logger.info(e.getMessage());
			throw new XunjiaException("增加企业出错,增加失败!!!");
		}
	}

	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.CompanyDao#deleteCompany(com.yam.michael.hibernate.pojo.Company)
	 * 删除企业
	 */
	@Override
	public void deleteCompany(Company company) throws XunjiaException {
		try {
			this.getHibernateTemplate().delete(company);
		} catch (DataAccessException e) {
			logger.info(e.getMessage());
			throw new XunjiaException("删除企业出错,删除失败!!!");
		}
	}

	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.CompanyDao#getCompanyById()
	 * 通过ID获得企业信息
	 */
	@Override
	public Company getCompanyById(long companyID) throws XunjiaException {
		try {
			return (Company) this.getHibernateTemplate().get(Company.class, companyID);
		} catch (DataAccessException e) {
			logger.info(e.getMessage());
			throw new XunjiaException("通过企业ID获取企业信息出错,获取失败!!!");
		}
	}

	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.CompanyDao#updateCompany(com.yam.michael.hibernate.pojo.Company)
	 * 更新企业信息
	 */
	@Override
	public void updateCompany(Company company) throws XunjiaException {
		try {
			this.getHibernateTemplate().saveOrUpdate(company);
		} catch (DataAccessException e) {
			logger.info(e.getMessage());
			throw new XunjiaException("更新企业出错,更新失败!!!");
		}
	}

}
